package com.xbs.dao.selfdriving;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.xbs.dao.conn.BaseDao;
import com.xbs.dao.conn.ParamSet;
import com.xbs.dao.conn.RowDatas;
import com.xbs.entity.ModelManageEntity;

/**
 * 后台车型管理Dao类
 * @author Administrator
 *
 */
public class ModelManageDao extends BaseDao {

	//声明一个结果处理对象
	private RowDatas<ModelManageEntity> modelmanage;
	
	/**
	 * 实例结果出来对象
	 */
	public ModelManageDao(){
		modelmanage = new getModelManage();
	}

	/**
	 * 1.查询所有车型信息
	 * @return
	 */
	public List<ModelManageEntity> selAll(){
		String sql = "select * from tb_car_model";
		return queryList(sql, modelmanage);
	}

	/**
	 * 2.根据车型编号查询车型信息
	 * @return
	 */
	public List<ModelManageEntity> selAll1(String modelid){
		String sql = "select * from tb_car_model where car_model_id = ?";
		return queryList(sql,new ParamSet(modelid), modelmanage);
	}
	
	/**
	 * 3.添加车型信息
	 * @return
	 */
	public int insert(String id, String name, String type, String year, Integer seating, Integer number, String fuel, String gps, String seat, String image, double cash, double insurance, double discount, double pledge){
		String sql = "insert into tb_car_model values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		return updateExecuted(sql, new ParamSet(id, name, type, year, seating, number, fuel, gps, seat, image, cash, insurance, discount, pledge));
	}
	
	/**
	 * 4.根据车型编号删除车型信息
	 * @return
	 */
	public int delete(String modelid){
		String sql = "delete from tb_car_model where car_model_id = ?";
		return updateExecuted(sql,new ParamSet(modelid));
	}
	
	/**
	 * 5.根据车型编号修改车型信息
	 * @return
	 */
	public int update(String id, String name, String type, String year, Integer seating, Integer number, String fuel, String gps, String seat, String image, double cash, double insurance, double discount, double pledge, String id1){
		String sql = "update tb_car_model set car_model_id=?, car_model_name=?, car_model_type=?, car_model_year=?, car_model_seating=?, car_model_door_number=?, car_model_fuel_type=?, car_model_gps=?, car_model_seat=?, car_model_image=?, car_model_rent_cash=?, car_model_insurance=?, company_discount=?, car_model_pledge=? where car_model_id = ? ";
		return updateExecuted(sql, new ParamSet(id, name, type, year, seating, number, fuel, gps, seat, image, cash, insurance, discount, pledge, id1));
	}
	
	private class getModelManage implements RowDatas<ModelManageEntity>{
		@Override
		public ModelManageEntity getRowData(ResultSet rs) throws SQLException {
			ModelManageEntity modelmanage = new ModelManageEntity();
			modelmanage.setCar_model_id(rs.getString("car_model_id"));
			modelmanage.setCar_model_name(rs.getString("car_model_name"));
			modelmanage.setCar_model_type(rs.getString("car_model_type"));
			modelmanage.setCar_model_year(rs.getString("car_model_year"));
			modelmanage.setCar_model_seating(rs.getInt("car_model_seating"));
			modelmanage.setCar_model_door_number(rs.getInt("car_model_door_number"));
			modelmanage.setCar_model_fuel_type(rs.getString("car_model_fuel_type"));
			modelmanage.setCar_model_gps(rs.getString("car_model_gps"));
			modelmanage.setCar_model_seat(rs.getString("car_model_seat"));
			modelmanage.setCar_model_image(rs.getString("car_model_image"));
			modelmanage.setCar_model_rent_cash(rs.getDouble("car_model_rent_cash"));
			modelmanage.setCar_model_insurance(rs.getDouble("car_model_insurance"));
			modelmanage.setCompany_discount(rs.getDouble("company_discount"));
			modelmanage.setCar_model_pledge(rs.getDouble("car_model_pledge"));
			return modelmanage;
		}
	}
}
